/**
 * 
 */
package com.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.demo.bean.Info;
import com.demo.dao.CityDataDAO;
import com.demo.service.CityDataService;
import com.demo.util.PageUtil;
import com.demo.util.Util;

/**
 * @author Issac
 *
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor={Exception.class}) 
public class CityDataServiceImpl implements CityDataService {
	
	@Autowired
	private CityDataDAO cityDataDAO;

	public CityDataDAO getCityDataDAO() {
		return cityDataDAO;
	}

	public void setCityDataDAO(CityDataDAO cityDataDAO) {
		this.cityDataDAO = cityDataDAO;
	}

	/* (non-Javadoc)
	 * @see com.demo.service.CityDataService#addCityData(com.demo.bean.Info)
	 */
	public int addCityData(Info info) {
		return 0;
	}

	public PageUtil searchIndex(String searchType, String searchPosition, int currentPage, int pageSize) {
		int totalPage = 0;
		PageUtil data = null;
		List<Info> infoList = null;
		
		Long totalCount = cityDataDAO.searchIndexCount(searchType, searchPosition);
		if (totalCount > 0){ 
			totalPage = Util.count2PageCount(totalCount.intValue(), pageSize);
			infoList = cityDataDAO.searchIndex(searchType, searchPosition, currentPage, pageSize);
		}
		
		if (Util.isNotEmpty(infoList)){
			data = new PageUtil();
			data.setTotalCount(totalCount.intValue());
			data.setTotalPage(totalPage);
			data.setPageContent(infoList);
			
		}
		
		return data;
	}

}
